import { HashRouter, BrowserRouter, Routes, Route, Link, useRoutes } from "react-router-dom"
import { Provider } from "react-redux"
import store from "@/store/index.js"


import Dashboard from "@/pages/dashboard";
import GoodForm from "@/pages/good/goodForm";
import GoodList from "@/pages/good/goodList";
import User from "@/pages/user";

import { asyncRoutes } from "./pages/index.jsx"
import Permission from "./Permission"


// accessRoutes 可访问的路由
function createRoutes(accessRoutes) {
    let result = [];
    accessRoutes.forEach(route => {
        if (route.path && route.element) {
            result.push(
                <Route key={route.key} path={route.path} element={route.element}></Route>
            )
        }
        if (route.children) {
            route.children.forEach(route => {
                result.push(
                    <Route key={route.key} path={route.path} element={route.element}></Route>
                )
            })
        }
    })
    return result;
}

// createRoutes(asyncRoutes)



function App() {
    return (
        //     <HashRouter>
        //         <Provider store={store}>
        //             <Routes>
        //                 {/* 在React中，一级路由是不需要指定出口 */}
        //                 <Route path="/" element={<Layout />}>
        //                     {/* 二级路由需要指定出口 */}
        //                     {/* <Route path="/dashboard" element={<Dashboard />}></Route>
        //                 <Route path="/good/list" element={<GoodList />}></Route>
        //                 <Route path="/user" element={<User />}></Route> */}

        //                     {
        //                         createRoutes(asyncRoutes)
        //                     }
        //                 </Route>
        //                 <Route path="/login" element={<Login />}></Route>
        //             </Routes>
        //         </Provider>
        //     </HashRouter>
        // );

        <HashRouter>
            <Provider store={store}>
                {/* <Routes>
                    <Route path="/" element={<Layout />}></Route>
                    <Route path="/login" element={<Login />}></Route>
                </Routes> */}

                {/* <Page /> */}

                <Permission />
            </Provider>
        </HashRouter>
    );
}
export default App;
